import MyEcharts from '@/components/my-echarts.vue';

// js中的一等公民
export default function getChartPageMixin (num) {
  return {
    name: 'App',
    components: {
      MyEcharts,
    },
    data () {
      return {
        data: this.getRandomData(),
        msg: 'this is page' + num,
      };
    },
    computed: {
      option () {
        return {
          xAxis: {
            type: 'category',
            data: this.data.map(d => d.day),
          },
          yAxis: {
            type: 'value'
          },
          series: [
            {
              data: this.data.map(d => d.value),
              type: 'line'
            }
          ],
        };
      },
    },
    methods: {
      getRandomData () {
        return [
          {
            day: 'Mon',
            value: Math.random() * 100,
          },
          {
            day: 'Mon',
            value: Math.random() * 100,
          },
          {
            day: 'Mon',
            value: Math.random() * 100,
          },
          {
            day: 'Mon',
            value: Math.random() * 100,
          },
        ];
      },
    },
    created () {
      setInterval(() => {
        this.data = this.getRandomData();
      }, 1000);
    },
    // 封装组件
    // electron
    // antv图表组件
  };

}